import com.lzw.gif.AnimatedGifEncoder;
import com.lzw.gif.GifDecoder;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class Main{
    public static void main(String[] args) {
        File file=new File(args[0]);
        try{
            AnimatedGifEncoder encoder=new AnimatedGifEncoder();
            GifDecoder decoder=new GifDecoder();
            File ff=new File(args[0]);
            decoder.read(new FileInputStream(ff));
            int delay=decoder.getDelay(0);
            int len=decoder.getFrameCount();
            int loop=decoder.getLoopCount();
            File f=new File(ff.getParent()+"/daofang.gif");
            FileOutputStream os=new FileOutputStream(f);
            encoder.start(os);
            encoder.setDelay(delay);
            encoder.setRepeat(loop);

            for(int i=0;i<len;i++){
                BufferedImage image2=decoder.getFrame(len-i-1);
                encoder.addFrame(image2);

            }


        }catch(IOException exception){


        }
    }
}